
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>条件构造器 · Diboot接口基础项目</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-vuejs-2/vue.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="数据库连接.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                



<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../基础.html">
            
                <a href="../基础.html">
            
                    
                    基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../基础/安装.html">
            
                <a href="../基础/安装.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../基础/开发规范.html">
            
                <a href="../基础/开发规范.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../基础/配置文件.html">
            
                <a href="../基础/配置文件.html">
            
                    
                    配置文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../基础/静态文件.html">
            
                <a href="../基础/静态文件.html">
            
                    
                    静态文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../基础/模板文件.html">
            
                <a href="../基础/模板文件.html">
            
                    
                    模板文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../基础/包说明.html">
            
                <a href="../基础/包说明.html">
            
                    
                    包说明
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../接口与访问.html">
            
                <a href="../接口与访问.html">
            
                    
                    接口与访问
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../接口与访问/添加新接口.html">
            
                <a href="../接口与访问/添加新接口.html">
            
                    
                    添加新接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../接口与访问/参数获取.html">
            
                <a href="../接口与访问/参数获取.html">
            
                    
                    参数获取
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../模型.html">
            
                <a href="../模型.html">
            
                    
                    模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../模型/添加模型.html">
            
                <a href="../模型/添加模型.html">
            
                    
                    添加模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../模型/模型校验.html">
            
                <a href="../模型/模型校验.html">
            
                    
                    模型校验
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../数据库.html">
            
                <a href="../数据库.html">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="数据库连接.html">
            
                <a href="数据库连接.html">
            
                    
                    数据库连接
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.2" data-path="条件构造器.html">
            
                <a href="条件构造器.html">
            
                    
                    条件构造器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>



                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                

                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >条件构造器</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x6761;&#x4EF6;&#x6784;&#x9020;&#x5668;"><b>1. </b>&#x6761;&#x4EF6;&#x6784;&#x9020;&#x5668;</a></li><ul><li><span class="title-icon "></span><a href="#&#x6DFB;&#x52A0;query&#x5B9E;&#x4F8B;"><b>1.1. </b>&#x6DFB;&#x52A0;Query&#x5B9E;&#x4F8B;</a></li><li><span class="title-icon "></span><a href="#&#x4F7F;&#x7528;query&#x6784;&#x5EFA;&#x7684;&#x6761;&#x4EF6;"><b>1.2. </b>&#x4F7F;&#x7528;Query&#x6784;&#x5EFA;&#x7684;&#x6761;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#&#x6761;&#x4EF6;&#x652F;&#x6301;"><b>1.3. </b>&#x6761;&#x4EF6;&#x652F;&#x6301;</a></li><ul><li><span class="title-icon "></span><a href="#add"><b>1.3.1. </b>add</a></li><li><span class="title-icon "></span><a href="#addin"><b>1.3.2. </b>addIn</a></li><li><span class="title-icon "></span><a href="#addnotin"><b>1.3.3. </b>addNotIn</a></li><li><span class="title-icon "></span><a href="#addlike"><b>1.3.4. </b>addLike</a></li><li><span class="title-icon "></span><a href="#addleftlike"><b>1.3.5. </b>addLeftLike</a></li><li><span class="title-icon "></span><a href="#addrightlike"><b>1.3.6. </b>addRightLike</a></li><li><span class="title-icon "></span><a href="#addgt"><b>1.3.7. </b>addGT</a></li><li><span class="title-icon "></span><a href="#addgte"><b>1.3.8. </b>addGTE</a></li><li><span class="title-icon "></span><a href="#addlt"><b>1.3.9. </b>addLT</a></li><li><span class="title-icon "></span><a href="#addlte"><b>1.3.10. </b>addLTE</a></li><li><span class="title-icon "></span><a href="#addnotequals"><b>1.3.11. </b>addNotEquals</a></li><li><span class="title-icon "></span><a href="#addnull"><b>1.3.12. </b>addNull</a></li><li><span class="title-icon "></span><a href="#addnotnull"><b>1.3.13. </b>addNotNull</a></li><li><span class="title-icon "></span><a href="#orderbyasc"><b>1.3.14. </b>orderByAsc</a></li><li><span class="title-icon "></span><a href="#orderbydesc"><b>1.3.15. </b>orderByDesc</a></li><li><span class="title-icon "></span><a href="#limit"><b>1.3.16. </b>limit</a></li></ul></ul></ul></div><a href="#&#x6761;&#x4EF6;&#x6784;&#x9020;&#x5668;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x6761;&#x4EF6;&#x6784;&#x9020;&#x5668;"><a name="&#x6761;&#x4EF6;&#x6784;&#x9020;&#x5668;" class="anchor-navigation-ex-anchor" href="#&#x6761;&#x4EF6;&#x6784;&#x9020;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x6761;&#x4EF6;&#x6784;&#x9020;&#x5668;</h1>
<blockquote>
<p>&#x4E3A;&#x4E86;&#x4FBF;&#x4E8E;&#x6784;&#x5EFA;&#x4E0E;&#x7BA1;&#x7406;&#x67E5;&#x8BE2;&#x6761;&#x4EF6;&#xFF0C;&#x5728;diboot-framework&#x5DF2;&#x7ECF;&#x5185;&#x7F6E;&#x4E86;<a href="">Query</a>&#x67E5;&#x8BE2;&#x6761;&#x4EF6;&#x7C7B;&#x3002;</p>
</blockquote>
<h2 id="&#x6DFB;&#x52A0;query&#x5B9E;&#x4F8B;"><a name="&#x6DFB;&#x52A0;query&#x5B9E;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#&#x6DFB;&#x52A0;query&#x5B9E;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x6DFB;&#x52A0;Query&#x5B9E;&#x4F8B;</h2>
<ul>
<li>&#x65B0;&#x5EFA;Query&#x5B9E;&#x4F8B;&#xFF0C;&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">String name = request.getParameter(<span class="hljs-string">&quot;name&quot;</span>);
Query query = <span class="hljs-keyword">new</span> Query(Student.F.name, name);
<span class="hljs-comment">// &#x6216;</span>
Query query = <span class="hljs-keyword">new</span> Query();
query.add(Student.F.name, name);
</code></pre>
<ul>
<li>Query&#x4E5F;&#x652F;&#x6301;&#x94FE;&#x5F0F;&#x8C03;&#x7528;&#xFF0C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">String name = request.getParameter(<span class="hljs-string">&quot;name&quot;</span>);
String phone = request.getParameter(<span class="hljs-string">&quot;phone&quot;</span>);
Query query = <span class="hljs-keyword">new</span> Query();
query.add(Student.F.name, name).add(Student.F.phone, phone);
</code></pre>
<h2 id="&#x4F7F;&#x7528;query&#x6784;&#x5EFA;&#x7684;&#x6761;&#x4EF6;"><a name="&#x4F7F;&#x7528;query&#x6784;&#x5EFA;&#x7684;&#x6761;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;query&#x6784;&#x5EFA;&#x7684;&#x6761;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x4F7F;&#x7528;Query&#x6784;&#x5EFA;&#x7684;&#x6761;&#x4EF6;</h2>
<ul>
<li>&#x5C06;query&#x5B9E;&#x4F8B;&#x8C03;&#x7528;build()&#x65B9;&#x6CD5;&#x540E;&#xFF0C;&#x4F20;&#x5165;&#x76F8;&#x5173;&#x7684;service&#x63A5;&#x53E3;&#x4E2D;&#xFF0C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">List&lt;Student&gt; students = studentService.getModelList(query.build());
</code></pre>
<h2 id="&#x6761;&#x4EF6;&#x652F;&#x6301;"><a name="&#x6761;&#x4EF6;&#x652F;&#x6301;" class="anchor-navigation-ex-anchor" href="#&#x6761;&#x4EF6;&#x652F;&#x6301;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x6761;&#x4EF6;&#x652F;&#x6301;</h2>
<ul>
<li>&#x5F53;query&#x5B9E;&#x4F8B;&#x8C03;&#x7528;&#x76F8;&#x5173;&#x6DFB;&#x52A0;&#x6761;&#x4EF6;&#x7684;&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x5C06;&#x4F1A;&#x50CF;&#x6761;&#x4EF6;&#x7ED3;&#x679C;&#x4E2D;&#x6DFB;&#x52A0;&#x4E00;&#x6761;&#x5143;&#x7D20;&#xFF0C;&#x6DFB;&#x52A0;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x6761;&#x4EF6;&#xFF0C;&#x5728;SQL&#x4E2D;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x4E5F;&#x5C06;&#x4E0D;&#x540C;&#x3002;</li>
<li>&#x5728;&#x6DFB;&#x52A0;&#x76F8;&#x5173;&#x7684;&#x6761;&#x4EF6;&#x540E;&#xFF0C;&#x5728;mapper.xml&#x4E2D;&#x4E5F;&#x9700;&#x8981;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x7684;&#x53D8;&#x91CF;&#x5B58;&#x5728;&#xFF0C;&#x65B9;&#x53EF;&#x751F;&#x6548;&#x3002;</li>
</ul>
<h3 id="add"><a name="add" class="anchor-navigation-ex-anchor" href="#add"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.1. add</h3>
<ul>
<li>&#x8C03;&#x7528;add&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String teacherId = request.getParameter(<span class="hljs-string">&quot;teacherId&quot;</span>);
query.add(Student.F.teacherId, teacherId);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.teacherId != null&quot;</span>&gt;</span> AND self.teacher_id=#{c.teacherId}<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addin"><a name="addin" class="anchor-navigation-ex-anchor" href="#addin"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2. addIn</h3>
<ul>
<li>&#x8C03;&#x7528;addIn&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String[] names = <span class="hljs-keyword">new</span> String[]{<span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>, <span class="hljs-string">&quot;&#x674E;&#x56DB;&quot;</span>};
query.addIn(Student.F.name, names);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.name_IN != null&quot;</span>&gt;</span>
    AND self.name IN
    <span class="hljs-tag">&lt;<span class="hljs-name">foreach</span> <span class="hljs-attr">item</span>=<span class="hljs-string">&quot;item&quot;</span> <span class="hljs-attr">collection</span>=<span class="hljs-string">&quot;c.name_IN&quot;</span> <span class="hljs-attr">open</span>=<span class="hljs-string">&quot;(&quot;</span> <span class="hljs-attr">separator</span>=<span class="hljs-string">&quot;,&quot;</span> <span class="hljs-attr">close</span>=<span class="hljs-string">&quot;)&quot;</span>&gt;</span>
        #{item}
    <span class="hljs-tag">&lt;/<span class="hljs-name">foreach</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addnotin"><a name="addnotin" class="anchor-navigation-ex-anchor" href="#addnotin"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.3. addNotIn</h3>
<ul>
<li>&#x8C03;&#x7528;addNotIn&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String[] names = <span class="hljs-keyword">new</span> String[]{<span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>, <span class="hljs-string">&quot;&#x674E;&#x56DB;&quot;</span>};
query.addNotIn(Student.F.name, names);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.name_NIN != null&quot;</span>&gt;</span>
    AND self.name NOT IN
    <span class="hljs-tag">&lt;<span class="hljs-name">foreach</span> <span class="hljs-attr">item</span>=<span class="hljs-string">&quot;item&quot;</span> <span class="hljs-attr">collection</span>=<span class="hljs-string">&quot;c.name_NIN&quot;</span> <span class="hljs-attr">open</span>=<span class="hljs-string">&quot;(&quot;</span> <span class="hljs-attr">separator</span>=<span class="hljs-string">&quot;,&quot;</span> <span class="hljs-attr">close</span>=<span class="hljs-string">&quot;)&quot;</span>&gt;</span>
        #{item}
    <span class="hljs-tag">&lt;/<span class="hljs-name">foreach</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addlike"><a name="addlike" class="anchor-navigation-ex-anchor" href="#addlike"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.4. addLike</h3>
<ul>
<li>&#x8C03;&#x7528;addLike&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String name = request.getParameter(<span class="hljs-string">&quot;name&quot;</span>);
query.addLike(Student.F.name, name);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.name_LIKE != null&quot;</span>&gt;</span> AND self.name like CONCAT(&apos;%&apos;,#{c.name_LIKE},&apos;%&apos;)<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addleftlike"><a name="addleftlike" class="anchor-navigation-ex-anchor" href="#addleftlike"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.5. addLeftLike</h3>
<ul>
<li>&#x8C03;&#x7528;addLeftLike&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String name = request.getParameter(<span class="hljs-string">&quot;name&quot;</span>);
query.addLeftLike(Student.F.name, name);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.name_LLIKE != null&quot;</span>&gt;</span> AND self.name like CONCAT(&apos;%&apos;,#{c.name_LLIKE})<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addrightlike"><a name="addrightlike" class="anchor-navigation-ex-anchor" href="#addrightlike"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.6. addRightLike</h3>
<ul>
<li>&#x8C03;&#x7528;addRightLike&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String name = request.getParameter(<span class="hljs-string">&quot;name&quot;</span>);
query.addRightLike(Student.F.name, name);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.name_RLIKE != null&quot;</span>&gt;</span> AND self.name like CONCAT(#{c.name_RLIKE},&apos;%&apos;)<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addgt"><a name="addgt" class="anchor-navigation-ex-anchor" href="#addgt"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.7. addGT</h3>
<ul>
<li>&#x8C03;&#x7528;addGT&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String score = request.getParameter(<span class="hljs-string">&quot;score&quot;</span>);
query.addGT(Student.F.score, score);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.score_GT != null&quot;</span>&gt;</span> AND self.score &amp;gt; #{c.score_GT}<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addgte"><a name="addgte" class="anchor-navigation-ex-anchor" href="#addgte"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.8. addGTE</h3>
<ul>
<li>&#x8C03;&#x7528;addGTE&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String score = request.getParameter(<span class="hljs-string">&quot;score&quot;</span>);
query.addGTE(Student.F.score, score);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.score_GTE != null&quot;</span>&gt;</span> AND self.score &amp;gt;= #{c.score_GTE}<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addlt"><a name="addlt" class="anchor-navigation-ex-anchor" href="#addlt"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.9. addLT</h3>
<ul>
<li>&#x8C03;&#x7528;addLT&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String score = request.getParameter(<span class="hljs-string">&quot;score&quot;</span>);
query.addLT(Student.F.score, score);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.score_LT != null&quot;</span>&gt;</span> AND self.score &amp;lt; #{c.score_LT}<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addlte"><a name="addlte" class="anchor-navigation-ex-anchor" href="#addlte"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.10. addLTE</h3>
<ul>
<li>&#x8C03;&#x7528;addLTE&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String score = request.getParameter(<span class="hljs-string">&quot;score&quot;</span>);
query.addLTE(Student.F.score, score);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.score_LTE != null&quot;</span>&gt;</span> AND self.score &amp;lt;= #{c.score_LTE}<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addnotequals"><a name="addnotequals" class="anchor-navigation-ex-anchor" href="#addnotequals"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.11. addNotEquals</h3>
<ul>
<li>&#x8C03;&#x7528;addNotEquals&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String teacherId = request.getParameter(<span class="hljs-string">&quot;teacherId&quot;</span>);
query.addNotEquals(Student.F.teacherId, teacherId);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.teacherId_NE != null&quot;</span>&gt;</span> AND self.teacher_id!=#{c.teacherId_NE}<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addnull"><a name="addnull" class="anchor-navigation-ex-anchor" href="#addnull"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.12. addNull</h3>
<ul>
<li>&#x8C03;&#x7528;addNull&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
query.addNull(Student.F.teacherId);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.teacherId_N != null&quot;</span>&gt;</span> AND self.teacher_id IS NULL<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="addnotnull"><a name="addnotnull" class="anchor-navigation-ex-anchor" href="#addnotnull"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.13. addNotNull</h3>
<ul>
<li>&#x8C03;&#x7528;addNotNull&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
query.addNotNull(Student.F.teacherId);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.teacherId_NN != null&quot;</span>&gt;</span> AND self.teacher_id IS NOT NULL<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<h3 id="orderbyasc"><a name="orderbyasc" class="anchor-navigation-ex-anchor" href="#orderbyasc"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.14. orderByAsc</h3>
<ul>
<li>&#x8C03;&#x7528;orderByAsc&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String name = request.getParameter(<span class="hljs-string">&quot;name&quot;</span>);
query.orderByAsc(Student.F.name, name);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">choose</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">when</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.ORDERBY_name != null&quot;</span>&gt;</span>ORDER BY self.name ${c.ORDERBY_name}<span class="hljs-tag">&lt;/<span class="hljs-name">when</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">otherwise</span>&gt;</span>ORDER BY self.id DESC<span class="hljs-tag">&lt;/<span class="hljs-name">otherwise</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">choose</span>&gt;</span>
</code></pre>
<h3 id="orderbydesc"><a name="orderbydesc" class="anchor-navigation-ex-anchor" href="#orderbydesc"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.15. orderByDesc</h3>
<ul>
<li>&#x8C03;&#x7528;orderByDesc&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
String name = request.getParameter(<span class="hljs-string">&quot;name&quot;</span>);
query.orderByDesc(Student.F.name, name);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">choose</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">when</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.ORDERBY_name != null&quot;</span>&gt;</span>ORDER BY self.name ${c.ORDERBY_name}<span class="hljs-tag">&lt;/<span class="hljs-name">when</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">otherwise</span>&gt;</span>ORDER BY self.id DESC<span class="hljs-tag">&lt;/<span class="hljs-name">otherwise</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">choose</span>&gt;</span>
</code></pre>
<h3 id="limit"><a name="limit" class="anchor-navigation-ex-anchor" href="#limit"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.16. limit</h3>
<ul>
<li>&#x8C03;&#x7528;addNotEquals&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-java">Query query = <span class="hljs-keyword">new</span> Query();
query.limit(<span class="hljs-number">20</span>);
</code></pre>
<ul>
<li>mapper.xml&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x6761;&#x4EF6;&#x884C;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;c.COUNT != null&quot;</span>&gt;</span>
    LIMIT #{c.COUNT}
<span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                

            </div>

            
                
                <a href="数据库连接.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 数据库连接">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"条件构造器","level":"1.5.2","depth":2,"previous":{"title":"数据库连接","level":"1.5.1","depth":2,"path":"数据库/数据库连接.md","ref":"数据库/数据库连接.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","sharing-plus","anchor-navigation-ex","theme-vuejs-2"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"theme-vuejs-2":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"mode":"float","pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"showLevel":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right","showGoTop":true,"isShowTocTitleIcon":true,"printLog":false,"multipleH1":true,"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false}},"sharing":{"qq":true,"all":["weibo","qq","linkedin","qzone","douban"],"douban":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Diboot接口基础项目","gitbook":"*","description":"Diboot接口基础项目"},"file":{"path":"数据库/条件构造器.md","mtime":"2018-11-08T08:51:40.941Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-11-10T15:09:18.458Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

